﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;

public partial class per_withdraw : MpageBase
{
    protected Model.SF_u_Pay addbankcard = null;
    protected Model.UsersAccount user_account = null;
    protected Model.CMember CMember = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (loginUserInfo != null && loginUserInfo.Id > 0)
        {
            addbankcard = BLL.SF_u_Pay.GetModelByUserId(loginUserInfo.Id);
            user_account = BLL.UsersAccount.GetModelByuser_id(loginUserInfo.Id);
            CMember = BLL.CMember.GetModel(loginUserInfo.Id);
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if(addbankcard!=null)
        {
            if (CMember.zhifuPassword.Equals(BLL.Security.MD5(zhifupass.Text.Trim())))
            {
                if (IsNumber(txmoney.Text))
                {
                    decimal totalm = decimal.Parse(txmoney.Text);
                    if (totalm > 0 && totalm <= user_account.total)
                    {
                        user_account.total = user_account.total - totalm;
                        user_account.txTotal = user_account.txTotal + totalm;
                        Model.SF_u_Pay u_pay = BLL.SF_u_Pay.GetModelByUserId(loginUserInfo.Id);
                        Model.SF_user_acc_cash tx = new Model.SF_user_acc_cash();
                        tx.s_status = 0;
                        tx.user_id = loginUserInfo.Id;
                        tx.credited = 0;
                        tx.total = totalm;
                        tx.fee = 0;
                        tx.addtime = DateTime.Now;
                        tx.adduser = loginUserInfo.realname;
                        tx.bankid = u_pay.BankID;
                        tx.branch = u_pay.BranchName;
                        tx.user_mem = u_pay.BankName;
                        tx.account = u_pay.AccountNumber;
                        tx.moduser = u_pay.AccountName;
                        if (BLL.UsersAccount.Update(user_account) > 0)
                        {
                            if (BLL.SF_user_acc_cash.Add(tx) > 0)
                            {
                                alertmessageAndGoback("提现申请操作成功！");
                            }
                        }
                    }
                    else
                    {
                        alertmessageAndGoback("提现金额必须大于0小于等于账户余额方可提金额！");
                    }
                }
                else
                {
                    alertmessageAndGoback("提现金额必须是数字！");
                }
            }
            else
            {
                alertmessageAndGoback("支付密码错误！");
            }
        }


    }
    public static bool IsNumber(string strNumber)
    {
        Regex regex = new Regex("[^0-9]");
        return !regex.IsMatch(strNumber);
    }
}